<!doctype html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>登录</title>
    <link rel="stylesheet" href="./vendor/simple-line-icons/css/simple-line-icons.css">
    <link rel="stylesheet" href="./vendor/font-awesome/css/fontawesome-all.min.css">
    <link rel="stylesheet" href="./css/styles.css">
</head>
<body>
<div class="page-wrapper flex-row align-items-center">
    <div class="container">
        <div class="row justify-content-center">
            <div class="col-md-5">
                <div class="card p-4">
                    <div class="card-header text-center text-uppercase h4 font-weight-light">
                        	健身房管理系统
                    </div>

                    <div class="card-body py-5">
                        <div class="form-group">
                            <label class="form-control-label">账户 : </label>
                            <input type="email" class="form-control" id="user-name">
                        </div>

                        <div class="form-group">
                            <label class="form-control-label">密码 : </label>
                            <input type="password" class="form-control" id="pass">
                        </div>
                        <div class="custom-control custom-checkbox mt-4">
                            <input type="checkbox" class="custom-control-input" id="isRememberPass">
                            <label class="custom-control-label" for="isRememberPass">记住密码</label>
                        </div>
                        <div class="form-group" style="margin-top: 40px;">
                            <button type="button"  class="btn btn-primary form-control" onclick="login()">登录</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    
</div>
    <div style="width: 100%; position: fixed;bottom: 0;padding:10px; background: #A2A2A3;"><span class="container" style="position: relative; width: 1200px; margin: auto;" >ICP证: <a style="color: #0000FF;" href="http://beian.miit.gov.cn" target="_blank">蜀ICP备2020025544号</a></span></div>

<script src="./vendor/jquery/jquery.min.js"></script>
<script src="./vendor/popper.js/popper.min.js"></script>
<script src="./vendor/bootstrap/js/bootstrap.min.js"></script>
<script src="https://cdn.bootcss.com/layer/3.1.0/layer.js"></script>
<script src="./js/config.js" ></script>
<script>
	$(document).ready(function () {
		
		$("#user-name").val(localStorage.getItem("admin_name"));
		var isRememberPass=localStorage.getItem("isAdminRememberPass");
		if(isRememberPass==1){
			$("#pass").val(localStorage.getItem("admin_pass"));
			$("#isRememberPass").prop("checked","checked");
		}
		
	});
	function login(){
		var name=$("#user-name").val();
		var pass=$("#pass").val();
		if(pass.length<1){
			layer.msg("密码不能为空");
			return;
		}
		layer.load(0, {shade: false});
		$.ajax({ 
		     type : "post", 
		     url : BSAE_PATH+"/admin/login",
		     dataType : 'json',
		     data : { 
		     	tel : name,
		     	pass : pass,
		     },
		     xhrFields:{ withCredentials:true},
		     success : function(result) {
		     	layer.closeAll();
			    if (result.code==200 ) {
			    	localStorage.setItem("admin_name",name);
			    	var isRememberPass= $("#isRememberPass").prop("checked");
			    	if(isRememberPass){
			    		localStorage.setItem("admin_pass",pass);
			    		localStorage.setItem("isAdminRememberPass",1);
			    	}else{
			    		localStorage.setItem("admin_pass","");
			    		localStorage.setItem("isAdminRememberPass",0);
			    	}
			    	
			    	location.href="index.html";
			    }else{ 
			       layer.msg(result.msg);
			    } 
		     },
		     error: function(){
		     	layer.closeAll();
		     	layer.msg("服务器异常");
		     }
	    });
		
	}
</script>
</body>
</html>
